﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace DDOS.Objects.Projectiles
{
    class Projectile0 : Projectile 
    {
        Rectangle spriteRectangle;
        public bool deleteMe;
        public Entity source;

        public Projectile0(int dam, int spe, Vector2 tar, Entity src)
        {
            target = tar;
            this.damage = dam;
            this.speed = spe;
            this.coordinates = src.Coordinates;
            source = src;
        }

        public override void InitializeComponents()
        {
            deleteMe = false;
            this.velocity = new Vector2(0, 0);
            this.life_time = 5;
            boundingObject = new BoundingRectangle((int)coordinates.X, (int)coordinates.Y, (int)coordinates.X + 8, (int)coordinates.Y + 8);
            this.texture = ImageManager2D.Instance.Bullet;
            spriteRectangle = new Rectangle((int)coordinates.X, (int)coordinates.Y, 8,8);
            CollisionEngine.Instance.Add(this.boundingObject);
        }

        public override void CollisionCallback(BoundingObject other, BoundingObject self)
        {
            if (other.parent.GetType() == typeof(Enemy0) && other == other.parent.boundingObject)
            {
                ((Enemy0)other.parent).Health -= ((Projectile0)self.parent).damage;
                deleteMe = true;
            }
            if (other.parent.GetType() == typeof(Boss1) && other == other.parent.boundingObject)
            {
                ((Boss1)other.parent).Health -= ((Projectile0)self.parent).damage;
                deleteMe = true;
            }
        }

        public override void Update(GameTime game_time)
        {
            base.Update(game_time);
            boundingObject.Move(velocity.X, velocity.Y);
            spriteRectangle.X = (int)coordinates.X;
            spriteRectangle.Y = (int)coordinates.Y;
        }
        public override void fire()
        {
            if ((this.coordinates - target).Length() >= (float)speed)
            {
                Vector2 v = (target - this.coordinates);
                v.Normalize();
                velocity = v * (float)speed;
            }
        }

        public override void Draw()
        {
            ScreenManager.Instance.CurrentSpriteBatch.Draw(texture, spriteRectangle, Color.White);
        }
    }
}
